package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;

public class TestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取虚拟路径
        System.out.println(request.getContextPath());
        //获取资源标识符
        System.out.println(request.getRequestURI());
        //根据指定属性名获取请求头
        System.out.println(request.getHeader("referer"));
        System.out.println(request.getHeader("user-agent"));
        System.out.println("--------------------------");
        //根据指定参数名获取参数
        System.out.println(request.getParameter("username"));
        System.out.println("---------------------");
        //获取所有参数的键值对
        Map<String, String[]> parameterMap = request.getParameterMap();
        for (String key:parameterMap.keySet()){
            System.out.println(key + "," + Arrays.toString(parameterMap.get(key)));
        }
    }
}
